import os
import subprocess

def pack(dst, src):
    arg=f'7za a {dst} {src.name}'
    subprocess.run(arg.split(), check=True, cwd=src.parent)

def walkfile(path, files):
    with os.scandir(path) as it:
        for entry in it:
            if os.path.isdir(entry.path):
                walkfile(entry.path, files)
            else:
                files.append(entry.path)
    return files

def myfilter(folders, dst, src):
    for i in folders:
        files = []
        files = walkfile(src+'/'+i.get('path'), files) 
        if i.get('after'):
            time = os.path.getctime(src+'/'+i.get('path')+'/'+i.get('after'))
            with os.scandir(src+'/'+i.get('path')) as it:
                for entry in it:
                    if os.path.getctime(entry.path) < time:
                        files.remove(entry.path)
        if i.get('exclude'):
            files.remove(src+'/'+i.get('path')+'/'+i.get('exclude'))
        for j in files:
            pack(dst, j)
